<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	    		xmlns:ui="http://java.sun.com/jsf/facelets"
	  			xmlns:h="http://java.sun.com/jsf/html"
	  			xmlns:f="http://java.sun.com/jsf/core"                
                xmlns:cs="http://myfaces.apress.com/custom"
				template="/WEB-INF/layouts/standard.xhtml"
				xmlns:a4j="http://richfaces.org/a4j"
				xmlns:rich="http://richfaces.org/rich"
				xmlns:c="http://java.sun.com/jstl/core"
				xmlns:bf="http://www.bssmanager.com/jsf">

	
	<ui:define name="formheader">
		<h2>Attendent</h2>
	</ui:define>

	<ui:define name="content">
						
			<h:messages errorClass="errors" style="color:#ff1111" />
						
			<h:form id="attendentform">
			
					<table width="100%">
						<tr class="norender">
							<td style="background-color: #FFBF80; font-weight: bolder; font-size: 10pt;" align="left">
								Select Patient
							</td>
						</tr>
						<tr>
							<td>
								<bf:admissionSelector controller="#{currentAttendentController}" selectMethod="selectAdmission" 
								reRender="selectedPatient1,selectedPatient2,selectedPatient3"/>
							</td>
						</tr>
						<tr class="norender">
							<td style="background-color: #FFBF80; font-weight: bolder; font-size: 10pt;" align="left">
								Patient Details
							</td>
						</tr>
						<tr>
							<td>
								<h:panelGroup id="selectedPatient1" style="display:#{currentAttendentController.admission.id le 0 ? 'none':'block' }">
									<h:outputText
										value="#{currentAttendentController.admission.dateOfExit == null ? '': 'Patient has Checked Out !'}"
										style="font-weight:bold; color:red" />
									<h:panelGrid columns="2">
										<h:outputLabel value="Name: " />
										<h:outputText value="#{currentAttendentController.admission.patient.name}" />
										<h:outputLabel value="Checked In: " />
										<h:outputText value="#{currentAttendentController.admission.dateOfAdmission}">
											<f:convertDateTime pattern="dd MMM yyyy HH:MM" />
										</h:outputText>							
									</h:panelGrid>				
								</h:panelGroup>							
							</td>
						</tr>
						<tr class="norender">
							<td style="background-color: #FFBF80; font-weight: bolder; font-size: 10pt;" align="center">
								Current Attendents
							</td>
						</tr>
						<tr>
							<td>
								<h:panelGroup id="selectedPatient2" style="display:#{currentAttendentController.admission.id le 0 ? 'none':'block' }">		
									<bf:attendent model="#{currentAttendentController.model}"
												addMethod="add"
												removeMethod="remove"
												selectMethod="selectAttendent"
												existing="attendents"
												reRender="selectedPatient3"
												data="#{currentAttendentController.data}"			
												controller="#{currentAttendentController}"/>
								</h:panelGroup>
							</td>
						</tr>
						<tr class="norender">
							<td style="background-color: #FFBF80; font-weight: bolder; font-size: 10pt;" align="center">
								All Attendents
							</td>
						</tr>
						<tr>
							<td>
								<h:panelGroup id="selectedPatient3" style="display:#{currentAttendentController.admission.id le 0 ? 'none':'block' }">
									<rich:dataTable id="allAttendents"  rowKeyVar="rowkey" rows="10"
													value="#{currentAttendentController.allAttendents}" var="aBean" align="center">
										<f:facet name="header">
											<h:outputText value="All Attendents"/>
										</f:facet>
										<rich:column>
											<f:facet name="header">S/N</f:facet>
											<h:outputText value="#{rowkey + 1} "/>
										</rich:column>							
										<rich:column>
											<f:facet name="header">Name</f:facet>
											<h:outputText value="#{aBean.name} "/>
										</rich:column>
										<rich:column>
											<f:facet name="header">Relationship</f:facet>
											<h:outputText value="#{aBean.relationship}" converter="#{relationshipConverter}"/>
										</rich:column>																	
										<rich:column>
											<f:facet name="header">Sex</f:facet>
											<h:outputText value="#{aBean.sex == 'M' ? 'Male' : 'Female'} "/>
										</rich:column>
										<rich:column>
											<f:facet name="header">Age</f:facet>
											<h:outputText value="#{aBean.age} "/>
										</rich:column>								
										
										<c:choose>
											<c:when test="#{empty currentAttendentController.allAttendents}">
												<f:facet name="footer">
													<h:outputText value="No Attendents Added..." />
												</f:facet>											
											</c:when>
											<c:otherwise>
												<f:facet name="footer">
													<rich:datascroller/>
												</f:facet>
											</c:otherwise>										
										</c:choose>										
												
									</rich:dataTable>
								</h:panelGroup>
							</td>
						</tr>
					</table>
			
								
			</h:form>
			
	</ui:define>
</ui:composition>